home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.tree.DefaultMutableTreeNode;
- import com.sun.java.swing.tree.TreeModel;
- import com.sun.java.swing.tree.TreePath;
- import com.sun.java.swing.tree.TreeSelectionModel;
-
- public class LargeTreeModelNode extends DefaultMutableTreeNode {
- protected AbstractTreeUI treeUI;
- protected boolean isExpanded;
- protected int childIndex;
-
- public LargeTreeModelNode(AbstractTreeUI treeUI, Object userObject, int childIndex) {
- super(userObject);
- this.treeUI = treeUI;
- this.childIndex = childIndex;
- }
-
- protected void addLargeTreeModelNode(LargeTreeModelNode newChild) {
- boolean added = false;
- int childIndex = newChild.getChildIndex();
- int counter = 0;
-
- for(int maxCounter = ((DefaultMutableTreeNode)this).getChildCount(); counter < maxCounter; ++counter) {
- if (((LargeTreeModelNode)((DefaultMutableTreeNode)this).getChildAt(counter)).getChildIndex() > childIndex) {
- added = true;
- ((DefaultMutableTreeNode)this).insert(newChild, counter);
- counter = maxCounter;
- }
- }
-
- if (!added) {
- ((DefaultMutableTreeNode)this).add(newChild);
- }
-
- }
-
- protected void adjustLargeRowCountBy(int changeAmount) {
- AbstractTreeUI var10000 = this.treeUI;
- var10000.largeRowCount += changeAmount;
- }
-
- public LargeTreeModelNode childAtModelIndex(int index) {
- for(int counter = ((DefaultMutableTreeNode)this).getChildCount() - 1; counter >= 0; --counter) {
- if (((LargeTreeModelNode)((DefaultMutableTreeNode)this).getChildAt(counter)).childIndex == index) {
- return (LargeTreeModelNode)((DefaultMutableTreeNode)this).getChildAt(counter);
- }
- }
-
- return null;
- }
-
- protected void childInsertedAtModelIndex(int index) {
- int counter = 0;
-
- for(int maxCounter = ((DefaultMutableTreeNode)this).getChildCount(); counter < maxCounter; ++counter) {
- LargeTreeModelNode aChild = (LargeTreeModelNode)((DefaultMutableTreeNode)this).getChildAt(counter);
- if (aChild.childIndex >= index) {
- while(counter < maxCounter) {
- ++((LargeTreeModelNode)((DefaultMutableTreeNode)this).getChildAt(counter)).childIndex;
- ++counter;
- }
- }
- }
-
- }
-
- protected void childRemovedAtModelIndex(int index) {
- int counter = 0;
-
- for(int maxCounter = ((DefaultMutableTreeNode)this).getChildCount(); counter < maxCounter; ++counter) {
- LargeTreeModelNode aChild = (LargeTreeModelNode)((DefaultMutableTreeNode)this).getChildAt(counter);
- if (aChild.childIndex >= index) {
- while(counter < maxCounter) {
- --((LargeTreeModelNode)((DefaultMutableTreeNode)this).getChildAt(counter)).childIndex;
- ++counter;
- }
- }
- }
-
- }
-
- public void collapse(boolean adjustTree) {
- if (this.isExpanded) {
- TreeSelectionModel selModel = null;
- TreePath[] selPaths;
- if (this.treeUI != null && (selModel = this.treeUI.getSelectionModel()) != null) {
- selPaths = selModel.getSelectionPaths();
- } else {
- selPaths = null;
- }
-
- if (this.isVisible()) {
- this.adjustLargeRowCountBy(-this.getTotalChildCount());
- }
-
- this.isExpanded = false;
- if (adjustTree) {
- this.didAdjustTree();
- this.treeUI.visibleNodesChanged();
- }
-
- this.treeUI.pathWasCollapsed(new TreePath(((DefaultMutableTreeNode)this).getUserObjectPath()));
- if (selPaths != null) {
- boolean shouldRemove = false;
- TreePath ourPath = new TreePath(((DefaultMutableTreeNode)this).getUserObjectPath());
-
- for(int counter = selPaths.length - 1; counter >= 0; --counter) {
- if (selPaths[counter] != null && ourPath.isDescendant(selPaths[counter]) && !ourPath.equals(selPaths[counter])) {
- shouldRemove = true;
- } else {
- selPaths[counter] = null;
- }
- }
-
- if (shouldRemove) {
- selModel.removeSelectionPaths(selPaths);
- }
- }
- }
-
- }
-
- protected void didAdjustTree() {
- }
-
- public void expand(boolean adjustTree) {
- if (!this.isExpanded) {
- boolean visible = this.isVisible();
- this.isExpanded = true;
- if (visible) {
- this.adjustLargeRowCountBy(this.getTotalChildCount());
- }
-
- if (adjustTree) {
- this.didAdjustTree();
- this.treeUI.visibleNodesChanged();
- }
-
- this.treeUI.pathWasExpanded(new TreePath(((DefaultMutableTreeNode)this).getUserObjectPath()));
- if (this.treeUI != null && visible) {
- int row = this.getRow();
- TreeSelectionModel selModel = this.treeUI.getSelectionModel();
- int cCount;
- if (selModel != null && (cCount = this.getTotalChildCount()) > 0 && selModel.isRowSelected(row) && selModel.isRowSelected(row + 1)) {
- TreePath[] paths = new TreePath[cCount];
-
- for(int counter = 0; counter < cCount; ++counter) {
- paths[counter] = this.treeUI.getPathForRow(counter + row + 1);
- }
-
- selModel.addSelectionPaths(paths);
- } else if (selModel != null) {
- selModel.resetRowSelection();
- }
- }
- }
-
- }
-
- public int getChildIndex() {
- return this.childIndex;
- }
-
- protected int getCountTo(int stopIndex) {
- int retCount = stopIndex + 1;
- int counter = 0;
-
- for(int maxCounter = ((DefaultMutableTreeNode)this).getChildCount(); counter < maxCounter; ++counter) {
- LargeTreeModelNode aChild = (LargeTreeModelNode)((DefaultMutableTreeNode)this).getChildAt(counter);
- if (aChild.childIndex >= stopIndex) {
- counter = maxCounter;
- } else {
- retCount += aChild.getTotalChildCount();
- }
- }
-
- if (super.parent != null) {
- return retCount + ((LargeTreeModelNode)((DefaultMutableTreeNode)this).getParent()).getCountTo(this.childIndex);
- } else if (!this.treeUI.isRootVisible()) {
- return retCount - 1;
- } else {
- return retCount;
- }
- }
-
- public TreeModel getModel() {
- return this.treeUI.getModel();
- }
-
- protected boolean getPathForRow(int row, int[] rowCounter, TreePath[] retPath, LargeTreeModelNode[] eNode, boolean[] isParentNode, int[] childIndex) {
- if (row == rowCounter[0]) {
- if (childIndex != null) {
- childIndex[0] = this.getChildIndex();
- }
-
- if (eNode != null) {
- eNode[0] = this;
- isParentNode[0] = false;
- }
-
- if (retPath != null) {
- retPath[0] = new TreePath(((DefaultMutableTreeNode)this).getUserObjectPath());
- }
-
- return true;
- } else {
- int var10002 = rowCounter[0]++;
- if (this.isExpanded) {
- int lastChildIndex = 0;
- TreeModel treeModel = this.getModel();
- int counter = 0;
-
- for(int maxCounter = ((DefaultMutableTreeNode)this).getChildCount(); counter < maxCounter; ++counter) {
- LargeTreeModelNode aNode = (LargeTreeModelNode)((DefaultMutableTreeNode)this).getChildAt(counter);
- int newChildIndex = aNode.childIndex;
- if (rowCounter[0] + (newChildIndex - lastChildIndex) > row) {
- if (childIndex != null) {
- childIndex[0] = row - rowCounter[0] + lastChildIndex;
- }
-
- if (retPath != null) {
- Object[] thisPath = ((DefaultMutableTreeNode)this).getUserObjectPath();
- int pLength = thisPath.length;
- Object[] newPath = new Object[pLength + 1];
- Object child = treeModel.getChild(super.userObject, row - rowCounter[0] + lastChildIndex);
- System.arraycopy(thisPath, 0, newPath, 0, pLength);
- newPath[pLength] = child;
- retPath[0] = new TreePath(newPath);
- }
-
- if (eNode != null) {
- eNode[0] = this;
- isParentNode[0] = true;
- }
-
- return true;
- }
-
- rowCounter[0] += newChildIndex - lastChildIndex;
- lastChildIndex = newChildIndex + 1;
- if (aNode.getPathForRow(row, rowCounter, retPath, eNode, isParentNode, childIndex)) {
- return true;
- }
- }
-
- int var17 = treeModel.getChildCount(super.userObject) - 1;
- if (var17 - lastChildIndex >= 0) {
- if (rowCounter[0] + (var17 - lastChildIndex) >= row) {
- if (childIndex != null) {
- childIndex[0] = row - rowCounter[0] + lastChildIndex;
- }
-
- if (retPath != null) {
- Object[] thisPath = ((DefaultMutableTreeNode)this).getUserObjectPath();
- int pLength = thisPath.length;
- Object[] newPath = new Object[pLength + 1];
- Object var18 = treeModel.getChild(super.userObject, row - rowCounter[0] + lastChildIndex);
- System.arraycopy(thisPath, 0, newPath, 0, pLength);
- newPath[pLength] = var18;
- retPath[0] = new TreePath(newPath);
- }
-
- if (eNode != null) {
- eNode[0] = this;
- isParentNode[0] = true;
- }
-
- return true;
- }
-
- rowCounter[0] += var17 - lastChildIndex + 1;
- }
- }
-
- return false;
- }
- }
-
- public int getRow() {
- LargeTreeModelNode parent = (LargeTreeModelNode)((DefaultMutableTreeNode)this).getParent();
- if (parent == null) {
- return this.treeUI.isRootVisible() ? 0 : -1;
- } else {
- return parent.getCountTo(this.childIndex);
- }
- }
-
- protected boolean getRow(Object[] path, int pathCounter, int pathLength, boolean isInPath, int[] rowCounter) {
- isInPath = isInPath && path[pathCounter].equals(super.userObject);
- if (isInPath) {
- ++pathCounter;
- if (pathCounter == pathLength) {
- return true;
- }
- }
-
- int var10002 = rowCounter[0]++;
- if (this.isExpanded) {
- TreeModel treeModel = this.getModel();
- int endIndex;
- if (isInPath && pathCounter + 1 == pathLength) {
- endIndex = treeModel.getIndexOfChild(super.userObject, path[pathLength - 1]);
- } else {
- endIndex = Integer.MAX_VALUE;
- }
-
- int lastChildIndex = 0;
- int newRowCount = rowCounter[0];
- int counter = 0;
-
- for(int maxCounter = ((DefaultMutableTreeNode)this).getChildCount(); counter < maxCounter; ++counter) {
- LargeTreeModelNode aNode = (LargeTreeModelNode)((DefaultMutableTreeNode)this).getChildAt(counter);
- int newChildIndex = aNode.childIndex;
- if (newChildIndex >= endIndex) {
- rowCounter[0] = newRowCount + (endIndex - lastChildIndex);
- return true;
- }
-
- newRowCount += newChildIndex - lastChildIndex;
- lastChildIndex = newChildIndex + 1;
- rowCounter[0] = newRowCount;
- if (aNode.getRow(path, pathCounter, pathLength, isInPath, rowCounter)) {
- return true;
- }
-
- newRowCount = rowCounter[0];
- }
-
- int var15 = treeModel.getChildCount(super.userObject) - 1;
- if (var15 >= 0) {
- if (var15 >= endIndex) {
- rowCounter[0] = newRowCount + (endIndex - lastChildIndex);
- return true;
- }
-
- rowCounter[0] += var15 - lastChildIndex + 1;
- }
- }
-
- return false;
- }
-
- public int getTotalChildCount() {
- if (!this.isExpanded()) {
- return 0;
- } else {
- int retCount = this.getModel().getChildCount(((DefaultMutableTreeNode)this).getUserObject());
-
- for(int counter = ((DefaultMutableTreeNode)this).getChildCount() - 1; counter >= 0; --counter) {
- retCount += ((LargeTreeModelNode)((DefaultMutableTreeNode)this).getChildAt(counter)).getTotalChildCount();
- }
-
- return retCount;
- }
- }
-
- public int getVisibleLevel() {
- return this.treeUI.isRootVisible() ? ((DefaultMutableTreeNode)this).getLevel() : ((DefaultMutableTreeNode)this).getLevel() - 1;
- }
-
- public boolean isExpanded() {
- return this.isExpanded;
- }
-
- public boolean isVisible() {
- LargeTreeModelNode parent = (LargeTreeModelNode)((DefaultMutableTreeNode)this).getParent();
- if (parent == null) {
- return true;
- } else {
- return parent.isExpanded() && parent.isVisible();
- }
- }
-
- public void modelChildCountChanged() {
- }
-
- public void toggleExpanded() {
- if (this.isExpanded()) {
- this.collapse(true);
- } else {
- this.expand(true);
- }
-
- }
- }
-